//
//  JXUITools.swift
//  GodoxFlash
//
//  Created by godox on 2021/12/7.
//

import Foundation


//MARK: - 安全区的一些数据
public struct JXUITools {
    
    /// 状态条高度
    public static var statusBarHeight: CGFloat {
        if #available(iOS 13.0, *) {
            let scene = UIApplication.shared.connectedScenes.first
            guard let windowScene = scene as? UIWindowScene else { return 0 }
            guard let window = windowScene.windows.first else { return 0 }
            return window.safeAreaInsets.top
        } else if #available(iOS 11.0, *) {
            guard let window = UIApplication.shared.windows.first else { return 0 }
            return window.safeAreaInsets.top
        }
        return 0
        
    }
    
    /// 底部安全距离
    public static var safeBottom: CGFloat {
        if #available(iOS 13.0, *) {
            let scene = UIApplication.shared.connectedScenes.first
            guard let windowScene = scene as? UIWindowScene else { return 0 }
            guard let window = windowScene.windows.first else { return 0 }
            return window.safeAreaInsets.bottom
        } else if #available(iOS 11.0, *) {
            guard let window = UIApplication.shared.windows.first else { return 0 }
            return window.safeAreaInsets.bottom
        }
        return 0
    }
    
    /// 导航栏高度
    public static var navBarHeight: CGFloat {
        let nav = UINavigationController()
        return nav.navigationBar.frame.height
    }
    
    /// 状态条 + 导航栏 的高度
    public static var statusAndNavbarHeight: CGFloat {
        return self.statusBarHeight + self.navBarHeight
    }
    
    /// 底部导航栏高度
    public static var tabBarHeight: CGFloat {
        return 49.0
    }
    
    public static var screenWidth: CGFloat {
        return UIScreen.main.bounds.width
    }
    
    public static var screenHeight: CGFloat {
        return UIScreen.main.bounds.height
    }

    public static var getWindows: UIWindow?{
        if let delegate: UIApplicationDelegate = UIApplication.shared.delegate {
            if let window = delegate.window {
                return window!
            }
        }
        ///UIWindowScene.windows
        return UIApplication.shared.windows.first
    }
    
    
}
